package com.example.demo.model.dto;

import com.example.demo.model.entity.user.User;
import com.example.demo.model.enums.UserStatus;
import com.example.demo.model.enums.UserTypeEnum;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;

@Data
public class UserDTO {
    private Long userId;
    private String username;
    private String name;
    private String email;
    private String avatar;
    private UserTypeEnum userType;
    private UserStatus status;
    private LocalDateTime createTime;

    public static UserDTO fromEntity(User user) {
        UserDTO dto = new UserDTO();
        // 复制除了 status 之外的其他属性
        BeanUtils.copyProperties(user, dto, "status");
        // 手动设置 status 字段
        dto.setStatus(UserStatus.of(user.getStatus()));
        return dto;
    }
}